package com.bite.LoopQueue.WaseSpace;

public class Demo {
    int cur;
    int dest;
    int[] Myqueue;

    public Demo(int k) {
        Myqueue = new int[k + 1];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        }
        Myqueue[cur] = value;
        //向后移动一位
        cur = (cur + 1) % Myqueue.length;
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        }
        dest = (dest + 1) % Myqueue.length;
        return true;
    }

    //队列从队列头开始进
    //队列首
    public int Front() {
        if (isEmpty()) {
            return -1;
        }
        return Myqueue[dest];
    }

    //队列尾
    public int Rear() {
        if (isEmpty()) {
            return -1;
        }
        int ret = cur == 0 ? Myqueue.length - 1 : cur - 1;
        return Myqueue[ret];
    }

    public boolean isEmpty() {
        if (cur == dest) {
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if ((cur + 1) % Myqueue.length == dest) {
            return true;
        }
        return false;
    }
}
